package com.t168.appinfo.controller.background;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.RequestWrapper;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.t168.appinfo.entity.BackendUser;
import com.t168.appinfo.service.background.backenduser.BackendUserService;

@Controller
@RequestMapping("/bgUser")
public class BgUserController {

	@Resource(name = "backendUserService")
	private BackendUserService backendUserService;
	
	public BackendUserService getBackendUserService() {
		return backendUserService;
	}

	public void setBackendUserService(BackendUserService backendUserService) {
		this.backendUserService = backendUserService;
	}



	/**
	 * 后台登陆页面
	 * @return
	 */
	@RequestMapping("/login.html")
	public String login(){
		
		return "jsp/backendlogin";
	}
	
	
	@RequestMapping(value = "/doLogin",method = RequestMethod.POST)
	public String doLogin(String userCode,String userPassword,HttpSession session,HttpServletRequest request){
		BackendUser bgUser = backendUserService.doLogin(userCode, userPassword);
		if(null == bgUser){
			request.setAttribute("doLoginError", "账号或密码错误");
			return "jsp/backendlogin";
		}
		
		session.setAttribute("bgUser", bgUser);
		return "jsp/backend/main";
	}
	
	
	@RequestMapping("/logout")
	public String logout(HttpSession session){
		session.removeAttribute("bgUser");
		return "redirect:/index.html";
	}
	
	
	
	
	
}
